//
//  LS_TabbarControllerConfig.m
//  breadPro
//
//  Created by 刘文超 on 2019/7/3.
//  Copyright © 2019 刘文超. All rights reserved.
//

#import "LS_TabbarControllerConfig.h"
#import "LS_MeViewController.h"
#import "LS_DestinationViewController.h"
#import "LS_FindViewController.h"
#import "LS_CityTravelViewController.h"

#import "LS_ViewModelServicesImpl.h"
#import "LS_CityTravelViewModel.h"
#import "LS_FindViewModel.h"
#import "LS_DestinatViewModel.h"
#import "LS_MeViewModel.h"

#import "LS_BaseNavViewController.h"



@interface LS_TabbarControllerConfig()

/**
底部控制器
 */
@property(nonatomic,strong)LS_CustomTabBarController *tabBarController;

/**
 数据服务
 */
@property(nonatomic,strong)LS_ViewModelServicesImpl *viewModelService;
/**
 首页
 */
@property(nonatomic,strong)LS_CityTravelViewModel *cityModelService;
/**
 发现
 */
@property(nonatomic,strong)LS_FindViewModel *findService;
/**
 设计
 */
@property(nonatomic,strong)LS_DestinatViewModel *destinceService;
/**
 我的
 */
@property(nonatomic,strong)LS_MeViewModel *meService;
@end

@implementation LS_TabbarControllerConfig
/**
 懒加载
 */
-(UITabBarController *)tabBarController
{
    if (!_tabBarController) {
        _tabBarController = [LS_CustomTabBarController tabBarControllerWithViewControllers:self.allControllers tabBarItemsAttributes:self.allTabBarAttributes];
            [self customizeTabBarAppearance];
    }return _tabBarController;
}
-(NSArray<UIViewController *> *)allControllers
{
    //创建总的数据服务
    self.viewModelService = [[LS_ViewModelServicesImpl  alloc]initWithModelServiceImpl];
    
    //首页
    self.cityModelService = [[LS_CityTravelViewModel alloc]initWithService:self.viewModelService];
    LS_CityTravelViewController *mainVC = [[LS_CityTravelViewController alloc]initWithViewModel:self.cityModelService];
    LS_BaseNavViewController *mainNav = [[LS_BaseNavViewController alloc]initWithRootViewController:mainVC];
    //发现
    self.findService = [[LS_FindViewModel alloc]initWithService:self.viewModelService];
    LS_FindViewController *findVC = [[LS_FindViewController alloc]initWithModel:self.findService];
    LS_BaseNavViewController *findNav = [[LS_BaseNavViewController alloc]initWithRootViewController:findVC];
    
    //设计
    self.destinceService = [[LS_DestinatViewModel alloc]initWithService:self.viewModelService];
    LS_DestinationViewController *destinVC = [[LS_DestinationViewController alloc]initWithModel:self.destinceService];
    LS_BaseNavViewController *destinNav = [[LS_BaseNavViewController alloc]initWithRootViewController:destinVC];
    
    
    //我的
    self.meService = [[LS_MeViewModel alloc]initWithService:self.viewModelService];
    LS_MeViewController *meVC = [[LS_MeViewController alloc]initWithModel:self.meService];
    LS_BaseNavViewController *meNav = [[LS_BaseNavViewController alloc]initWithRootViewController:meVC];
    
    
    
    NSArray *viewControllers = @[mainNav,findNav,destinNav,meNav];
    return viewControllers;

}
-(NSArray<NSDictionary *> *)allTabBarAttributes
{
    NSDictionary *dict1 = @{LS_TabBarItemTitle : @"城市游",LS_TabBarItemImage : @"root_tab_recommand_25x25_" ,LS_TabBarItemSelectImage : @"root_tab_recommand_hl_25x25_"};
    NSDictionary *dict2 = @{LS_TabBarItemTitle : @"发现",LS_TabBarItemImage : @"root_tab_discover_25x25_" ,LS_TabBarItemSelectImage : @"root_tab_discover_hl_25x25_"};
    NSDictionary *dict3 = @{LS_TabBarItemTitle : @"设计",LS_TabBarItemImage : @"root_tab_msg_25x25_" ,LS_TabBarItemSelectImage : @"root_tab_msg_hl_25x25_"};
    NSDictionary *dict4 = @{LS_TabBarItemTitle : @"我的",LS_TabBarItemImage : @"root_tab_me_25x25_" ,LS_TabBarItemSelectImage : @"root_tab_me_hl_25x25_"};
    NSArray *tabAttributes = @[dict1,dict2,dict3,dict4];
    
    return tabAttributes;
    
}
#pragma mark -
#pragma mark tabbarItem 的选中和不选中文字和背景图片属性、tabbar 背景图片属性设置
-(void)customizeTabBarAppearance
{
    //普通状态下的属性
    NSMutableDictionary *nomerDict = [[NSMutableDictionary alloc]init];
    nomerDict[NSForegroundColorAttributeName] = [UIColor grayColor];
    //选中状态下的属性
    NSMutableDictionary *selectDict = [[NSMutableDictionary alloc]init];
    selectDict[NSForegroundColorAttributeName] = LS_SetColor(74, 189, 204);
    
    //设置文字属性
    UITabBarItem *tabbar = [UITabBarItem appearance];
    [tabbar setTitleTextAttributes:nomerDict forState:UIControlStateNormal];
    [tabbar setTitleTextAttributes:selectDict forState:UIControlStateSelected];
    
    //设置图片 去掉tabbar自带的顶部阴影
    [[UITabBar appearance] setBackgroundImage:[UIImage new]];
    [[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
    
}
@end
